package com.YKFuse.bean.operation.alert;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

/**
 * @author yuank
 * @version 1.0.0
 * @date 2025/2/11 15:11:15
 */
public class YKFuseAlertServiceDefaultImpl implements YKFuseAlertService {

    private static final Logger log = LoggerFactory.getLogger(YKFuseAlertServiceDefaultImpl.class);

    /**
     *【熔断告警】检测到方法调用失败！
     * Bean: OrderService (org.example.service.OrderService)
     * 方法: placeOrder
     * 参数: [12345, "productA", 2]
     * 返回值/异常: NetworkTimeoutException: Request timed out
     * 时间: 2025-02-15 14:30:12
     */

    @Override
    public void alert(Object bean, Method method, Object[] params, Throwable throwable) {
        log.warn("【熔断告警】检测到方法调用失败！\n" +
                        "Bean: {} ({})\n" +
                        "方法: {}\n" +
                        "参数: {}\n" +
                        "返回值/异常: {}\n" +
                        "时间: {}",
                bean.getClass().getSimpleName(), bean,
                method.getName(),
                Arrays.toString(params),
                throwable != null ? throwable.getMessage() : "未知异常",
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
        );
    }
}